<template>
  <div class="login-container">
    <!-- 背景装饰 -->
    <div class="background-decoration">
      <div class="circle circle-1"></div>
      <div class="circle circle-2"></div>
      <div class="circle circle-3"></div>
      <div class="gradient-overlay"></div>
    </div>

    <!-- 登录卡片 -->
    <div class="login-card">
      <div class="login-header">
        <h1 class="login-title">账户登录</h1>
        <p class="login-subtitle">请输入您的账号信息</p>
      </div>

      <!-- 登录类型切换 -->
      <div class="login-type-tabs">
        <button
            class="tab-btn"
            :class="{ active: loginType === 'admin' }"
            @click="loginType = 'admin'"
        >
          管理员登录
        </button>
        <button
            class="tab-btn"
            :class="{ active: loginType === 'merchant' }"
            @click="loginType = 'merchant'"
        >
          商户登录
        </button>
      </div>

      <!-- 登录表单 -->
      <form class="login-form" @submit.prevent="handleLogin">
        <div class="form-group">
          <label for="username" class="form-label">用户名</label>
          <div class="input-wrapper">
            <i class="icon user-icon"></i>
            <input
                type="text"
                id="username"
                v-model="form.username"
                placeholder="请输入用户名"
                required
                class="form-input"
            />
          </div>
        </div>

        <div class="form-group">
          <label for="password" class="form-label">密码</label>
          <div class="input-wrapper">
            <i class="icon lock-icon"></i>
            <input
                type="password"
                id="password"
                v-model="form.password"
                placeholder="请输入密码"
                required
                class="form-input"
            />
          </div>
        </div>

        <div class="form-options">
          <label class="remember-me">
            <input type="checkbox" v-model="rememberMe" class="checkbox" />
            <span>记住我</span>
          </label>
          <a href="#" class="forgot-password">忘记密码?</a>
        </div>

        <button type="submit" class="login-btn">
          <span>登录</span>
          <i class="icon arrow-icon"></i>
        </button>
      </form>
    </div>
  </div>
</template>

<script>
import server from "../utils/request.js";
import router from "../router/index.js";
export default {
  data() {
    return {
      loginType: 'admin', // 默认管理员登录
      form: {
        username: '',
        password: ''
      },
      rememberMe: false
    };
  },
  methods: {
    async handleLogin() {
      // 登录处理逻辑
      console.log(`登录类型: ${this.loginType}`);
      console.log('登录信息:', this.form);
      if (this.loginType==='admin'){
        //管理员登录，向后端发送请求
        let {data:data} = await server.post("/admin/login",this.form)
        sessionStorage.setItem("token",data.data)
        sessionStorage.setItem("role","admin");
        router.push("/home")
      }
      if (this.loginType==='merchant'){
        //管理员登录，向后端发送请求
        let {data:data} = await server.post("/merchant/login",this.form)
        sessionStorage.setItem("token",data.data)
        sessionStorage.setItem("role","merchant")
        router.push("/merchantHome")
      }
      // 这里可以添加实际登录逻辑，如API调用等
      alert(`${this.loginType === 'admin' ? '管理员' : '商户'}登录成功！`);
    }
  }
};
</script>

<style scoped>
/* 基础样式 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.login-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* 背景装饰 */
.background-decoration {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.circle {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.7;
}

.circle-1 {
  width: 600px;
  height: 600px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  top: -200px;
  right: -100px;
  animation: float 15s ease-in-out infinite;
}

.circle-2 {
  width: 500px;
  height: 500px;
  background: linear-gradient(135deg, #4facfe, #00f2fe);
  bottom: -150px;
  left: -100px;
  animation: float 12s ease-in-out infinite 2s;
}

.circle-3 {
  width: 400px;
  height: 400px;
  background: linear-gradient(135deg, #fa709a, #fee140);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation: float 18s ease-in-out infinite 4s;
}

.gradient-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(10px);
}

/* 登录卡片 */
.login-card {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 420px;
  padding: 3rem;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(15px);
  border-radius: 1.5rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.login-card:hover {
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.15);
  transform: translateY(-5px);
}

/* 登录头部 */
.login-header {
  text-align: center;
  margin-bottom: 2.5rem;
}

.login-title {
  font-size: 2rem;
  font-weight: 700;
  color: #2d3748;
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, #667eea, #764ba2);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.login-subtitle {
  color: #718096;
  font-size: 1rem;
}

/* 登录类型切换 */
.login-type-tabs {
  display: flex;
  margin-bottom: 2rem;
  border-radius: 0.75rem;
  overflow: hidden;
  background: #f7fafc;
}

.tab-btn {
  flex: 1;
  padding: 0.75rem;
  border: none;
  background: transparent;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  color: #4a5568;
}

.tab-btn.active {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
}

.tab-btn:not(.active):hover {
  background: rgba(102, 126, 234, 0.1);
}

/* 表单样式 */
.login-form {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: #4a5568;
}

.input-wrapper {
  position: relative;
}

.form-input {
  width: 100%;
  padding: 1rem 1rem 1rem 2.5rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.75rem;
  font-size: 1rem;
  transition: all 0.3s ease;
  background: #f7fafc;
}

.form-input:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
  background: white;
}

/* 图标样式 */
.icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: #a0aec0;
}

.user-icon::before {
  content: "👤";
}

.lock-icon::before {
  content: "🔒";
}

.arrow-icon::before {
  content: "→";
}

/* 表单选项 */
.form-options {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
}

.remember-me {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #4a5568;
  font-size: 0.875rem;
  cursor: pointer;
}

.checkbox {
  width: 1rem;
  height: 1rem;
  accent-color: #667eea;
}

.forgot-password {
  color: #667eea;
  font-size: 0.875rem;
  text-decoration: none;
  transition: color 0.3s ease;
}

.forgot-password:hover {
  color: #764ba2;
  text-decoration: underline;
}

/* 登录按钮 */
.login-btn {
  padding: 1rem;
  border: none;
  border-radius: 0.75rem;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
}

.login-btn:hover {
  background: linear-gradient(135deg, #5a6fdd, #6a4299);
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(102, 126, 234, 0.2);
}

/* 底部链接 */
.login-footer {
  text-align: center;
  margin-top: 2rem;
  color: #4a5568;
  font-size: 0.875rem;
}

.register-link {
  color: #667eea;
  text-decoration: none;
  font-weight: 500;
  transition: color 0.3s ease;
}

.register-link:hover {
  color: #764ba2;
  text-decoration: underline;
}

/* 动画 */
@keyframes float {
  0% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-30px);
  }
  100% {
    transform: translateY(0px);
  }
}

/* 响应式设计 */
@media (max-width: 768px) {
  .login-card {
    padding: 2rem;
    margin: 0 1rem;
  }

  .circle-1 {
    width: 400px;
    height: 400px;
  }

  .circle-2 {
    width: 300px;
    height: 300px;
  }

  .circle-3 {
    width: 250px;
    height: 250px;
  }
}
</style>